<?php

namespace App\Http\Service;

use App\Util\Result;
use App\Model\User;

trait ServiceUser{

    /**
     * @return mixed
     * 管理员列表
     */
    public static function getList($name,$limit){
        if (empty($name)) {
            $res = User::orderBy('id','desc')->paginate($limit);
        } else {
            $res = User::orderBy('id','desc')->where("account","like", '%'.$name.'%')->paginate($limit);
        }
        return Result::success()->setData($res);
    }

    /**
     *获取单个id记录
     */
    public static function getOne($id) {
        $res = User::where("id", $id)->first();
        return Result::success()->setData($res);
    }

    /**
     *更新记录
     */
    public static function updateUser($input, $id) {
        $res = User::where("id", $id)->update($input);
        return Result::success()->setData($res);
    }

    /**
     *删除记录
     */
    public static function deleteUser($id) {
        $res = User::where("id", $id)->delete();
        return Result::success()->setData($res);
    }

    /**
     * 禁用、启用
     */
    public static function able($id,$able) {
        $res = User::where("id", $id)->update(['status' => $able]);
        return Result::success()->setData($res);
    }
    
    public static function getByAccount($account) {
    	$res = User::where("account",$account)->select('id')->get();
    	return Result::success()->setData($res);
    }
    
}


